package com.skcc.ts.nsi.service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class MEDateHandler {

	// 금일 String값 반환
	public static String calcToday() {
		Date date = Calendar.getInstance().getTime();
		String today = toDateString(date, "yyyyMMdd");
		return today;
	}

	// 일일 증감된 날짜 String값 반환
	public static String calcOldDay(int nDay) {
		Date date = addDate((Calendar.getInstance().getTime()), nDay);
		String oldDay = toDateString(date, "yyyyMMdd");
		return oldDay;
	}

	// Date날짜 String 변환
	public static String toDateString(Date date, String dateFormat) {
		if (date == null)
			return null;
		SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
		return sdf.format(date);
	}

	// 날짜 증감
	public static Date addDate(Date date, int nDay) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.DATE, nDay);
		return cal.getTime();
	}

	// 두자리 숫자 표현
	public static String pad(int num) {
		String number = null;
		if (num >= 10) {
			number = String.valueOf(num);
		} else {
			number = "0" + String.valueOf(num);
		}
		return number;
	}

}
